Page({
  data: {
    loading: false,
    prescriptionList: [
      {
        id: 1,
        doctorName: '王医生',
        deptName: '内科',
        date: '2025-04-20',
        diagnosis: '普通感冒',
        medicines: [
          { name: '感冒通颗粒', usage: '一次1袋，一日3次，饭后服用', days: 3 },
          { name: '布洛芬缓释胶囊', usage: '一次1粒，发热时服用，一日最多3次', days: 3 }
        ]
      },
      {
        id: 2,
        doctorName: '李医生',
        deptName: '消化内科',
        date: '2025-04-15',
        diagnosis: '胃炎',
        medicines: [
          { name: '奥美拉唑肠溶胶囊', usage: '一次1粒，一日2次，饭前半小时服用', days: 7 },
          { name: '铝碳酸镁咀嚼片', usage: '一次2片，一日3次，餐后服用', days: 7 }
        ]
      },
      {
        id: 3,
        doctorName: '张医生',
        deptName: '皮肤科',
        date: '2025-04-10',
        diagnosis: '荨麻疹',
        medicines: [
          { name: '氯雷他定片', usage: '一次1片，一日1次，饭后服用', days: 5 },
          { name: '复方倍氯米松樟脑乳膏', usage: '一日2-3次，外用涂抹患处', days: 7 }
        ]
      }
    ]
  },

  onLoad() {
    wx.setNavigationBarTitle({
      title: '我的处方'
    })
    
    // 模拟加载
    this.setData({ loading: true })
    setTimeout(() => {
      this.setData({ loading: false })
    }, 800)
  },
  
  // 查看处方详情
  viewPrescriptionDetail(e) {
    const id = e.currentTarget.dataset.id
    const prescription = this.data.prescriptionList.find(item => item.id === id)
    
    if (prescription) {
      this.setData({
        currentPrescription: prescription,
        showPrescriptionDetail: true
      })
    }
  },
  
  // 关闭处方详情
  closePrescriptionDetail() {
    this.setData({
      showPrescriptionDetail: false
    })
  },
  
  // 下拉刷新
  onPullDownRefresh() {
    this.setData({ loading: true })
    setTimeout(() => {
      this.setData({ loading: false })
      wx.stopPullDownRefresh()
    }, 800)
  }
}) 